<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_存储箱条码管理</title>
<script type="text/javascript">
  
  $(function() {
		$("#queryForm").validate(); 
  });
  
  //查询
  function ajaxQuery(){
      
      //$("#sel_num").hide();
      $("#forselect").hide()
	  $("#btn_printCode").hide();
      $("#curCode").html('');
  
	  if( $("#queryForm").valid()){
	  
	         var customerCode=$("#_customerCode").val();
		     var warehouseCode=$("#_warehouseCode").val();
		     
		     $.ajax({
					type : 'post',
					url : '${ctx}/v2/stockBoxCode/ajaxQuery',
					data : {
						customerCode:customerCode,
						warehouseCode:warehouseCode
					},
					dataType : 'json',
					success : function(data) {
					    var status=data.status;
					    if(status=='success'){
					       var stockBoxCode=data.stockBoxCode;
					       
					       $("#curCode").html(stockBoxCode.curCode);
					       $("#curRankno").val(stockBoxCode.curRankno);
					       $("#warehouseCode").val(stockBoxCode.warehouseCode);
					       $("#customerCode").val(stockBoxCode.customerCode);
					       
					       
					       //$("#sel_num").show();
					        $("#forselect").show()
					       $("#btn_printCode").show();
					       
					    }else{
					       alert("网络繁忙，请稍后重试...");
					    }
					
					},
					error : function() {
						alert("网络繁忙，请稍后重试...");
					}
				});
	     
	  
	  }
     
  }
  
  //init打印机
  function initPrinter() {
		//var indexLength = getPrinterCount();
		//var tempString = "";
		//for ( var i = 0; i < indexLength; i++) {
		//	var name = getPrinterName(i);
		//	tempString += "<option value='"+name+"'>" + name + "</option>";
		//}
		//$("#printerBody").html(tempString);
		//$("#printerBody_2").html(tempString);
	  packFormPrinter("printerBody");
	  packFormPrinter("printerBody_2");
  }
  
  //获得打印机的个数
  function getPrinterCount() {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_COUNT();
  }
	
  //根据打印机序号获得打印机名称
  function getPrinterName(iPrinterNO) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_NAME(iPrinterNO);
  }
  
  //打印
  function clickPrinter() {
	  
	    var num=$("#sel_num").val();
	    var curRankno=$("#curRankno").val();
	    var warehouseCode=$("#warehouseCode").val();
	    var customerCode=$("#customerCode").val();
	    
	    //修改数据库条码序号
	    $.ajax({
			type : 'post',
			url : '${ctx}/v2/stockBoxCode/ajaxUpdateRankno',
			data : {
				customerCode:customerCode,
				warehouseCode:warehouseCode,
				num:num
			},
			dataType : 'json',
			success : function(data) {
			    if(data=true){
			       var _curRankno=Number(curRankno)+Number(num);
			       $("#curRankno").val(_curRankno);
			       
			       //打印
				   var printName = $("#printerBody").val();
				   for(i=0;i<num;i++){
						var rankno=curRankno+'';
						while(rankno.length<5){rankno='0'+rankno;}
						var boxCode='B'+warehouseCode+rankno;
						curRankno=Number(curRankno)+Number(1);
						printBarCode(printName, boxCode);
						$("#curCode").html(boxCode);
				  }
			       
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
		
  }
  
  function printBarCode(printName, taskName) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(1, 600, 320, "");
		LODOP.ADD_PRINT_BARCODE(25, 10, 200, 45, "128B", taskName);
		LODOP.SET_PRINT_STYLE("FontName","SimHei");
	    LODOP.SET_PRINT_STYLE("FontSize",25);
		LODOP.ADD_PRINT_TEXT(70, 28, 200,100,taskName);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT();
		}
  }
  
  //打印
  function clickPrinter2() {
	    var myCode=$("#myCode").val().trim();
	    var printName = $("#printerBody_2").val();
		printBarCode(printName, myCode);
		$("#myCode").val('');
		$("#myCode").focus();
  }
  
  

</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		     
		     <form class="form-search" id="queryForm" style="margin-top: 10px;">
			 	<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
			 	<label class="input-group-text">商家：</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="form-control required" onchange="ajaxAreaGroup(this,'_warehouseCode')">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
				</div>
			 	</div>
			 	
			 	<div class="col-sm-3">
							<div class="input-group col-sm-12">
			 	
				<label class="input-group-text">仓库：</label>
				 <select  name="_warehouseCode"  id="_warehouseCode" class="form-control required" >
				 <option value=""></option>
				</select>
				
				</div>
				</div>
				
				<div class="col-sm-4">
							<div class="input-group col-sm-12">
			    <button class="btn btn-info" type="button" style="margin-left: 10px;" onclick="ajaxQuery();">搜索</button>
			    
			    </div>
			    </div>
			    </div>
		    </form>
	</div>
	</div>
	</div>
	</div>
	
		<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>					
			    <th>当前条码</th>
			    <th>打印数量</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
			<tr style="height: 50px;">
			   <td id="curCode" style="width: 250px;"></td>
			   <td style="width: 250px;">
			   <div id="forselect" style="display: none">
			     <select  name="sel_num" id="sel_num" >
			            <option value="1">1</option> 
			            <option value="5">5</option>  
				        <option value="10" selected="selected">10</option>  
				        <option value="20">20</option>
				 </select> 
				</div>
			   </td>
			   <td  >
			      <input type="hidden" id="customerCode" />
			      <input type="hidden" id="warehouseCode" />
			      <input type="hidden" id="curRankno" />
			      
			      <a href="#selextPrinter"  data-toggle="modal" class="btn btn-info" onclick="initPrinter();" style="display: none;" id="btn_printCode">打印条码</a>
			   </td>
			</tr>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">自定义打印</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				 <div class="form-group row">
			 <div class="col-sm-3">
			 <div class="input-group col-sm-12">
<span class="input-group-text">  条码：  </span>
<input type="text" class="form-control"  id="myCode">
			 </div>
			</div>
			 <div class="col-sm-9"> 
			 <a href="#selextPrinter2"  data-toggle="modal" class="btn btn-info" onclick="initPrinter();"  id="btn_printCode" >打印条码</a> 
			 </div>
</div> 
				
	</div>
	</div>
	</div>
	</div>
	
	<!-- 打印条码窗体1 -->
	<div  class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter">
		 <div class="modal-dialog" style="width:1000">
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">打印条码</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <select id="printerBody" name="printerBody" style="width: 300px;"></select>
		  </div>
			
		  <div class="modal-footer">
		      <a role="button" id="printer" class="btn btn-primary" onclick="clickPrinter();"  data-dismiss="modal">开始打印</a>
			  <button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		  </div></div>
	</div>
	
	<!-- 打印条码窗体2 -->
	<div class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter2">
		<div class="modal-dialog" style="width:1000">
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">打印条码</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <select id="printerBody_2" name="printerBody_2" style="width: 300px;"></select>
		  </div>
			
		  <div class="modal-footer">
		      <a role="button"  class="btn btn-primary" onclick="clickPrinter2();"  data-dismiss="modal">开始打印</a>
			  <button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		  </div>
		  </div>
	</div>
</section>
</body>
</html>
